{include_core file="m/lib/header.html" title="订单详情" center="center"}
{if $order_info.pay_type == 1 && $order_info.progress == 1 && user_helper::get_login_way() == 'lenovowap' && $is_direct_pay ==1}
<script type="text/javascript">
$(function(){
  var st = '{user_helper::get_lenovo_st()}';
  var order_id = '{order_helper::order_id_encode($order_info.id)}';
  var order_price = '{$order_info.price}';
  var order_name = '{order_helper::order_id_encode($order_info.id)}';
  var cb = "{AnUrl('order/index')}";
  LenovoID.doPay(order_id, order_price, 'www.newbd.com', order_name, st, cb);
})
</script>
{/if}
{if $order_info.pay_type == 2 && $order_info.progress == 1 && $is_direct_pay ==1 && is_weixin()}
<script type="text/javascript">
$(function(){
  var order_id = "{$order_info.id}";
  if(is_weixin()) {
      if(!order_id) {
        showMsg('支付失败，请重新支付');
      }
      var url     = siteUrl + '/openapi/weixin/pay/index';
      var data    = { 'order_id':order_id };

      $.post(url, data, function(json){
        if (json.info != 'ok') {
          // thisBtn.attr('is-post', 0);
          showMsg(json.info);
          return false;
        } else {
          if(typeof WeixinJSBridge == "undefined" || typeof WeixinJSBridge.invoke == 'undefined') {
            setTimeout(function(){
                jsApiCall(json.pay_info);
            }, 2500);
          } else {
            onBridgeReady(json.pay_info);
          }
        }

      }, 'json').error(function(){
        showMsg('请求失败，请重新请求');
      });
  } else {
    showMsg('无法使用微信支付，请使用微信客户端打开网页', 0, 2000);
    return;
  }
  
});

function onBridgeReady(paydata){
  // alert(JSON.stringify(paydata));
  //         return false;
    WeixinJSBridge.invoke('getBrandWCPayRequest',paydata,
        function(res){
            WeixinJSBridge.log(res.err_msg);
            if (res.err_msg != 'get_brand_wcpay_request:ok') {
              // alert(res.err_msg);
              if(res.err_msg == 'get_brand_wcpay_request:cancel') {
                showMsg('已取消支付', 0, 2000);
              }
              // thisBtn.attr('is-post', 0);
              return false;
            }
            window.location = siteUrl + '/order/index';
        }
    );
}

function jsApiCall(paydata){
     if( document.addEventListener ){
         document.addEventListener('WeixinJSBridgeReady', onBridgeReady(paydata), false);
     }else if (document.attachEvent){
         document.attachEvent('WeixinJSBridgeReady', onBridgeReady(paydata)); 
         document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(paydata));
     }
}
</script>
{/if}
<div class="details">
  <div class="details-order clearfix">
    <div class="details-date">
      <p>订单单号：<span>{order_helper::order_id_encode($order_info.id)}</span></p>
      <p>订单金额：<span>￥{$order_info.price}</span></p>
      <p>订单日期：<span>{$order_info.add_time}</span></p>
      {*<p>订单状态：<span style="color: red;">{order_config::$dealer_progress[$order_info.progress]}</span></p>*}
    </div>
    <div class="details-buttn">
      <p class="total-money">总金额：<span>￥{$order_info.price}</span></p>
      <div class="right">
        {if $order_info.progress == 1}
        <a class="button-curr" href="{order_helper::get_order_pay_url($order_info.id)}">去支付</a>
        {elseif $order_info.progress == 20}
        <a href="{AnUrl("service/slt_service?order_id={$order_info.id}")}">申请售后</a>
        {/if}
        {if $order_info.progress < 15 && $order_info.progress > 0}
        <a href="javascript:void(0);" class="js_cancelOrder" data-id="{$order_info.id}">取消订单</a>
        {/if}
        {if $order_info.express_no}
        <a href="javascript:void(0);" class="js_viewExpress" data-order_id="{$order_info.id}">查看物流</a>
        {/if}
      </div>
    </div>
  </div>
  <div class="details-logistics hidden js_expressInfo">
    <h2 class="tit">物流信息</h2>
    <ul>
      <li class="curr clearfix">
        <i class="circle"></i>
        <div class="l-detail">
          <p class="address">到北京市【北京集散中心】</p>
          <p class="time">2015-12-13   01:23:46</p>
        </div>
      </li>
      <li class="clearfix">
        <i class="circle"></i>
        <div class="l-detail">
          <p class="address">到北京市【北京集散中心】</p>
          <p class="time">2015-12-13   01:23:46</p>
        </div>
      </li>
    </ul>
  </div>
  <div class="details-content">
    {foreach $order_detail as $k=>$v}
    <dl class="details-dl clearfix">
      <dt><img src="{_image($v.goods_cover)}" width="92" /></dt>
      <dd>
        <div class="details-top">{if $v.is_gift > 0}<a href="javascript:void(0);">赠品</a>{elseif $v.is_promotion>0}<a href="javascript:void(0);">加购价</a>{/if}<p>{$v.goods_title} {goods_helper::get_sku_property_value($v.sku_id)}</p></div>
        {if $v.is_gift>0}
        {$goods_price = _uri('sku', $v.sku_id, 'price')}
        {else}
        {$goods_price = $v.goods_price}
        {/if}
      <p class="details-txt">售价： <span>{$goods_price}</span>元</p>
      <p class="details-txt">数量： <span>{$v.goods_num}</span></p>
      <p class="details-txt">小计：<span>{$v.goods_price*$v.goods_num}</span>元</p>
      </dd>
    </dl>
    {/foreach}
  </div>
  <div class="details-address">
    <p>{$order_info.receiver} {$order_info.mobile}</p>
    <p>{$order_info.province} {$order_info.city} {$order_info.district} {$order_info.address}</p>
  </div>
  <div class="details-pay">
    <ul>
      <li>
        <h2>支付方式</h2>
        <p>{openapi_config::$pay_type[$order_info.pay_type]['title']}支付</p>
      </li>
      {*
      <li>
        <h2>配送方式</h2>
        <p>{$order_info.express_title}(运费：{$order_info.post_price}元)</p>
      </li>
      *}
      <li>
        <h2>发票信息</h2>
        <p>{if $order_info.invoice_type == 1}电子发票{if order_helper::get_order_refund_url($order_info['id'])}<a href="{order_helper::get_order_refund_url($order_info['id'])}" style="color:#0000ff">（下载电子发票）</a>{/if}{elseif $order_info.invoice_type == 2}{$order_info.invoice_title}{else}不开发票{/if}</p>
      </li>
    </ul>
  </div>
</div>
  <!--我的订单details  end-->
<script>
$(function(){
  $('.js_viewExpress').on('click', function(){
    var orderId = $(this).data('order_id');
    var url     = siteUrl+'/express/ajax_express_info';
    var _this   = $(this);
    if ($(this).data('checked') == 1) {
      return false;
    }
    $(this).data('checked', 1);
    $('.js_expressInfo').show();
      $('.js_expressInfo').find('ul').html('<li class="curr clearfix">\
        <i class="circle"></i>\
        <div class="l-detail">\
          <p class="address">快递信息查询中，请稍后...</p>\
        </div>\
      </li>');
    $.get(url, { order_id:orderId, order:'desc' }, function(json){
      if (json.info == 'ok') {
        var newHtml = '';
        var data = json.json.data;
        var dataLenght = data.length;
        var currClass = '';
        for (var i = 0; i < dataLenght; i++) {
          var time = data[i]['time'].split(' ');
          if (i == 0) {
            currClass = 'curr';
          } else {
            currClass = '';
          }
          newHtml += '<li class="'+currClass+' clearfix">\
        <i class="circle"></i>\
        <div class="l-detail">\
          <p class="address">'+data[i]['context']+'</p>\
          <p class="time">'+time[0]+'   '+time[1]+'</p>\
        </div>\
      </li>'
        }
      } else {
        var newHtml = '<li class="curr clearfix">\
            <i class="circle"></i>\
            <div class="l-detail">\
              <p class="address">快递信息查询失败，请稍后重试</p>\
            </div>\
          </li>';
        _this.data('checked', 0);
      }
      $('.js_expressInfo').find('ul').html(newHtml);
    }, 'json');
  });
  
  /**
   * 取消订单
   */
  $('.js_cancelOrder').on('click', function(){
    var orderId = $('.js_cancelOrder').data('id');
    var url     = siteUrl+'/order/cancel_order';
    if (btnClick() === false) {
      return false;
    }
    showConfirm('您确定要取消当前订单吗？', function(){
      $.post(url, { order_id:orderId, reason:'手机取消，暂无选择' }, function(json){
        if (json.info == 'ok') {
          location.href = location.href;
        } else {
          showMsg(json.info, 1);
        }
      }, 'json');
    }, function(){
      btnClick('reset');
    });
  });
});
</script>
{include_core file="m/lib/footer.html"  center="center"}